#!/usr/bin/env ruby
# The Config class is used to encapsulate RedBook's user configuration file 
# (rbconfig.yml) which can be placed in your $HOME (or %HOME%) directory or in 
# RedBook's top level directory.
#
# The configuration is accessible from everywhere via @RedBook::Config.instance@
class RedBook::Config
	
	include Singleton
	include RedBook::Utils
	
	attr_accessor :data, :macros, :macros_array
	
	# Initialize the main Config public variables.
	def initialize
		@macros = {}
		@macros_array = []
		load
	end
	
	# Load rbconfig.yml into memory, and set convenient public variables for
	# variables and macros.
	def load
		@data = load_yaml_file(Hash, RedBook::CONFIG)
		@data.each_pair do |i, v|
			if i.to_s.match(/^m_/) then
				index = "#{i.to_s.gsub(/^m_/, '')}"
				@macros[:"#{index}"] = v
				@macros_array << ":#{index}"
			end
			raise ConfigError, "Empty Configuration File" unless !@data.blank?
		end
		@data
	end

end
